//
//  TuiJianView.m
//  KCFurProject
//
//  Created by ios程序员 on 15/11/3.
//  Copyright (c) 2015年 ios程序员. All rights reserved.
//

#import "TuiJianView.h"

@implementation TuiJianView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tuijianLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, self.frame.size.width, 30)];
        [self addSubview:self.tuijianLabel];
        self.tuijianLabel.font = [UIFont systemFontOfSize:19];
        self.tuijianLabel.text = @"最新推荐";
        
        self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, self.frame.size.width/2, self.frame.size.height- 40)];
        [self.imageView1 setImage:[UIImage imageNamed:@""]];

        self.imageView1.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.imageView1];
        
        self.imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width/2+2, 40, self.frame.size.width/6-5, self.frame.size.height - 40*HEIGH)];
        self.imageView2.backgroundColor = [UIColor blackColor];
        [self.imageView2 setImage:[UIImage imageNamed:@"xx"]];

        [self addSubview:self.imageView2];
        
        self.imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width/3*2+2, 40, self.frame.size.width/6-5, self.frame.size.height- 40*HEIGH)];
        self.imageView3.backgroundColor = [UIColor yellowColor];
        [self.imageView3 setImage:[UIImage imageNamed:@"xx"]];

        [self addSubview:self.imageView3];
        
        self.imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width/6*5+2, 40, self.frame.size.width/6-5, self.frame.size.height - 40*HEIGH)];
        [self.imageView4 setImage:[UIImage imageNamed:@"xx"]];

        self.imageView4.backgroundColor = [UIColor blueColor];
        [self addSubview:self.imageView4];
        
        self.jishiLabel = [[UILabel alloc] initWithFrame:CGRectMake(5*WIDTH, 50*HEIGH, self.frame.size.width/2 , 50*HEIGH)];
        self.jishiLabel.text = @"距2015.12.12日还有:";
        self.jishiLabel.textColor = [UIColor redColor];
        self.jishiLabel.font = [UIFont systemFontOfSize:17];
        [self addSubview:self.jishiLabel];
        
        
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 100*HEIGH, self.frame.size.width/2-40*HEIGH, 30*HEIGH)];
        [self addSubview:self.timeLabel];
        self.timeLabel.backgroundColor = [UIColor blackColor];
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        self.timeLabel.textColor = [UIColor whiteColor];
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeLabelCkick:) userInfo:nil repeats:YES];
        
    }
    return self;
}

//倒计时
- (void)timeLabelCkick:(NSTimer *)timer
{
    NSCalendar *calender = [NSCalendar currentCalendar];
    NSDateComponents *components = [[NSDateComponents alloc] init];
    [components setYear:2015];
    [components setMonth:12];
    [components setDay:12];
    [components setHour:0];
    [components setMinute:0];
    [components setSecond:0];
    NSDate *fireDate = [calender dateFromComponents:components];
    NSDate *today = [NSDate date];
    unsigned int unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitDay |NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitWeekday  ;
    NSDateComponents *day = [calender components:unitFlags fromDate:today toDate:fireDate options:0];
    self.timeLabel.text = [NSString stringWithFormat:@"%ld天 %ld:小时%ld:分%ld秒 ",(long)[day day] , (long)[day hour], (long)[day minute], (long)[day second]];
    
}





@end
